import { LocalStorage } from './services/local-storage.service';
import { Component } from "@angular/core";
import { AdMob } from "@admob-plus/ionic/ngx";
import { SplashScreen } from "@ionic-native/splash-screen/ngx";
import { StatusBar } from "@ionic-native/status-bar/ngx";
import { Platform } from "@ionic/angular";
import { EventsService } from "./services/events.service";
import { Global } from "./services/global.service";

declare let cordova: any;
@Component({
	selector: "app-root",
	templateUrl: "app.component.html",
	styleUrls: ["app.component.scss"]
})
export class AppComponent {

	banner: any = {};
	constructor(
		private platform: Platform,
		private splashScreen: SplashScreen,
		private statusBar: StatusBar,
		private global: Global,
		private events: EventsService,
		private adMob: AdMob
	) {
		this.initializeApp();
		this.events.on(Global.IAP, async () => {
			await this.banner.hide();
		});
	}

	initializeApp() {
		this.platform.ready().then(() => {
			this.statusBar.styleDefault();
			this.splashScreen.hide();
			this.configAd();
			this.global.firstLaunch();
		});
	}

	private async configAd() {
		if (this.global.needShowAd) {
			await this.adMob.requestTrackingAuthorization();
			await this.adMob.start()
			this.banner = new this.adMob.BannerAd({
				adUnitId: Global.ADMOB_BANNER,
			})
			await this.banner.show();
			cordova.plugins.BytedanceUnionAd.SplashAd.show(Global.BD_SPLASH);
		}
	}

}
